#include<bits/stdc++.h>
//~ #define int long long
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i,  b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=2e6+5,Mod=998244353;
//char buf[(1<<21)+5],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
void chmx(int &x,int y){(x<y)&&(x=y);}
void chmn(int &x,int y){(x>y)&&(x=y);}
typedef __int128_t i128;
i128 _base=1;
inline int mol(int x){return x-Mod*(_base*x>>64);}
inline void Add(int &x,int y){x=mol(x+y+Mod);}
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
bool SSS;
int n,q;
char s[N];
int qzh[N],hzh[N];
int st1[N][21],st2[N][21];
int lg[N];
inline int qry1(int l,int r){
	int k=lg[r-l+1];
	return max(st1[l][k],st1[r-(1<<k)+1][k]);
}
inline int qry2(int l,int r){
	int k=lg[r-l+1];
	return max(st2[l][k],st2[r-(1<<k)+1][k]);
}
int suf[N],pre[N];
bool vis[N];
bool TTT;
signed main(){
//~ cerr<<(&TTT-&SSS)/1024/1024<<"Mib";
	_base=(_base<<64)/Mod;
	freopen("good.in","r",stdin);
	freopen("good.out","w",stdout);
	n=read(),q=read();
	scanf("%s",s+1);
	For(i,1,n) qzh[i]=qzh[i-1]+(s[i]=='0'?1:-1);
	Rof(i,n,1)hzh[i]=hzh[i+1]+(s[i]=='0'?1:-1);
	lg[0]=-1;
	For(i,1,n)st1[i][0]=qzh[i],lg[i]=(lg[i/2]+1);
	For(i,1,n)st2[i][0]=hzh[i];
	//~ For(i,1,n) cout<<st3[i][0]<<" ";
	For(j,1,20){
		For(i,1,n){
			if(i+(1<<(j-1))>n) break;
			st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]);
			st2[i][j]=max(st2[i][j-1],st2[i+(1<<(j-1))][j-1]);
		}
	}if(n<=10000&&q<=10000){
		int res=0;
		while(q--){
			int l=read(),r=read();
			int ss=0;
			int ans=0;
			For(i,l,r){
				if(s[i]=='1') ss++;
				else ss--;
				if(ss<0) vis[i-1]=1,ans++,ss++;
			}
			ss=0;
			Rof(i,r,l){
				if(s[i]=='1')ss++;
				else ss--;
				if(vis[i])ss++;
				if(ss<0) ans++,ss++;
			}
			res^=ans;
			//~ printf("%lld\n",ans);
		}
		printf("%d\n",res);
		return 0;
	}
	int ans=0;
	while(q--){
		int l=read(),r=read();
		//~ ans^=max(qry1(l,r)-qzh[l-1]+(s[r]=='0'),qry2(l,r)-hzh[r+1]+(s[l]=='0'));
		ans^=max(qry1(l,r)-qzh[l-1]+(s[r]=='0'),qry2(l,r)-hzh[r+1]+(s[l]=='0'));
		//~ printf("%lld\n",min(qry1(l,r)-qzh[l-1],qry2(l,r)-hzh[r+1]));
	}
	printf("%d\n",ans);
#ifdef LOCAL
    Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}
/*
10 5
0001001111
1 6
1 10
5 7
4 7
4 6
*/
